package com.ts.enterprise.common.response;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class Page {

    @ApiModelProperty("第几页, 默认为1")
    private Long currentIndex;

    @ApiModelProperty("单页数量, 默认为5")
    private Integer countPerPage;


    @ApiModelProperty("总页数")
    private Long pageCount;

    @ApiModelProperty("记录总数")
    private Long count;

    @JsonIgnore
    private Integer limit;

    @JsonIgnore
    private Long offset;

    public Page() {
    }

    public Page(Long pageCount, Long count) {
        this.pageCount = pageCount;
        this.count = count;
    }

    public Page(Long currentIndex, Integer countPerPage, Long count) {
        this.currentIndex = currentIndex;
        this.countPerPage = countPerPage;
        this.count = count;
    }

    public Integer getLimit() {
        if (countPerPage == null) {
            return 5;
        }
        return countPerPage;
    }

    public Long getCurrentIndex() {
        return currentIndex == null ? 1 : currentIndex;
    }

    public Integer getCountPerPage() {
        return countPerPage == null ? 10 : countPerPage;
    }

    public Long getOffset() {
        return getCountPerPage() * (getCurrentIndex() - 1);
    }
}
